﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel.Description;
using System.ServiceModel.Channels;
using System.ServiceModel.Dispatcher;

namespace PServiceBus.WCF.NetTcpTransport {
    internal class DataSerializerOperationAttribute : Attribute, IOperationBehavior {
        private bool _preserveReferences = false;
        private int _maxItemsInObjectGraph = 65536;

        public DataSerializerOperationAttribute(bool preserveReferences, int maxItemsInObjectGraph) {
            _preserveReferences = preserveReferences;
            _maxItemsInObjectGraph = maxItemsInObjectGraph;
        }

        public DataSerializerOperationAttribute() : this(true, Int32.MaxValue) { }

        public void AddBindingParameters(OperationDescription description, BindingParameterCollection parameters) { }

        public void ApplyClientBehavior(OperationDescription description, ClientOperation proxy) {
            IOperationBehavior innerBehavior = new DataSerializerOperationBehavior(description, _preserveReferences, _maxItemsInObjectGraph);
            innerBehavior.ApplyClientBehavior(description, proxy);
        }

        public void ApplyDispatchBehavior(OperationDescription description, DispatchOperation dispatch) {
            IOperationBehavior innerBehavior = new DataSerializerOperationBehavior(description, _preserveReferences, _maxItemsInObjectGraph);
            innerBehavior.ApplyDispatchBehavior(description, dispatch);
        }

        public void Validate(OperationDescription description) { }
    }
}
